package com.lancoo.ccas53.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lancoo.ccas53.aspect.LogAnnotation;
import com.lancoo.ccas53.entity.*;
import com.lancoo.ccas53.exception.BizException;
import com.lancoo.ccas53.mapper.TeachingClassWeekMapper;
import com.lancoo.ccas53.pojo.common.PageInfo;
import com.lancoo.ccas53.pojo.dto.ResultDto;
import com.lancoo.ccas53.pojo.dto.SetCourseDto;
import com.lancoo.ccas53.pojo.dto.SubGroupDto;
import com.lancoo.ccas53.pojo.vo.*;
import com.lancoo.ccas53.service.*;
import com.lancoo.ccas53.util.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 教学任务相关模块
 * </p>
 *
 * @author quin.song
 * @since 2023-02-21
 */
@Api(tags = "教学任务")
@RestController
@RequestMapping("/teachTask")
public class TeachTaskController {
    @Resource
    private CourseService courseService;
    @Resource
    private TeachingClassService teachingClassService;
    @Resource
    private StudentService studentService;
    @Resource
    private TeachingClassStudentService teachingClassStudentService;
    @Resource
    private TeachingClassWeekService teachingClassWeekService;
    @Resource
    private SubClassService subClassService;
    @Resource
    private MonitorService monitorService;
    @Resource
    private SubClassGroupService subClassGroupService;
    @Resource
    private ScheduleService scheduleService;
    @Resource
    private SplitClassService splitClassService;
    @Resource
    private TeachingClassWeekMapper teachingClassWeekMapper;

    @ApiOperation("获取设置课程环节参数列表")
    @GetMapping(value = "/getSetCourseList")
    public ResponseObject<SetCourseDto<Course>> getCourseList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                              @ApiParam(value = "0全部 1已设置 2未设置") @RequestParam(required = false) Integer dataRange,
                                                              @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                              @ApiParam(value = "课程类别id") @RequestParam(required = false) String courseTypeId,
                                                              @ApiParam(value = "课程性质 1必修 2选修") @RequestParam(required = false) Integer courseNature,
                                                              @ApiParam(value = "1、课程 2、环节") @RequestParam(required = false) Integer flag,
                                                              @ApiParam(value = "课程名模糊查") @RequestParam(required = false) String keyword,
                                                              @ApiParam(value = "参数是否设置  0、未设置  1、已设置") @RequestParam(required = false) Integer parameterSet,
                                                              @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                              @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        Page<Course> page = new Page<>(currentPage, pageSize);
        return ResponseObject.ofSuccess(courseService.getCourseList(page, taskId, dataRange, baseCollegeId, courseTypeId, courseNature, flag, keyword, parameterSet));
    }

    @ApiOperation("设置课程参数")
    @PostMapping(value = "/setCourseParams")
    @LogAnnotation(operationType = "2", operationContent = "设置课程参数")
    public ResponseObject<Boolean> setCourseParams(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                   @ApiParam(value = "参数设置", required = true) @RequestBody @Valid CourseInput courseInput) {
        return ResponseObject.ofSuccess(courseService.setCourseParams(taskId, courseInput));
    }

    @ApiOperation("获取侧边栏课程环节列表")
    @GetMapping(value = "/getCourseTree")
    public ResponseObject<List<CourseTreeVo>> getCourseTree(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                            @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                            @ApiParam(value = "课程名模糊查询") @RequestParam(required = false) String keyword) {
        return ResponseObject.ofSuccess(courseService.getCourseTree(taskId, baseCollegeId, keyword));
    }

    @ApiOperation("根据课程获取培养方案")
    @GetMapping(value = "/getPlanByCourse")
    public ResponseObject<SetCourseDto<PlanTeaching>> getPlanByCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                      @ApiParam(value = "课程id") @RequestParam(required = false) Long courseId,
                                                                      @ApiParam(value = "校区") @RequestParam(required = false) Integer campusId,
                                                                      @ApiParam(value = "1主修 2辅修") @RequestParam(required = false) Integer studyNature,
                                                                      @ApiParam(value = "学院id") @RequestParam(required = false) String baseCollegeId,
                                                                      @ApiParam(value = "0其他 1预选课", required = true) @RequestParam Integer flag) {
        return ResponseObject.ofSuccess(courseService.getPlanByCourse(taskId, courseId, campusId, studyNature, baseCollegeId, flag));
    }

    @ApiOperation("根据课程获取教学班")
    @GetMapping(value = "/getByCourse")
    public ResponseObject<PageInfo<TeachingClass>> getTeachingClassByCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                            @ApiParam(value = "课程id") @RequestParam(required = false) Long courseId,
                                                                            @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                            @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                            @ApiParam(value = "0无需选课 1在线选课 2:分级教学 3:预选教学班") @RequestParam(required = false) Integer teachingClassType,
                                                                            @ApiParam(value = "教学班名称") @RequestParam(required = false) String keyword,
                                                                            @ApiParam(value = "排课  教学班id", required = true) @RequestParam(required = false) Long teachingClassId) {
        return ResponseObject.ofSuccess(courseService.getTeachingClassByCourse(taskId, courseId, currentPage, pageSize, teachingClassType, keyword, teachingClassId));
    }

    @ApiOperation("分不同教师上课，拆教学班")
    @PostMapping(value = "/spiltClassForTeacher")
    public ResponseObject<List<TeachingClass>> spiltClassForTeacher(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                    @ApiParam(value = "教学班id", required = true) @RequestParam Long teachingClassId,
                                                                    @ApiParam(value = "分班数量", required = true) @RequestParam Long splitNum,
                                                                    @ApiParam(value = "授课类型", required = true) @RequestParam Integer hourType,
                                                                    @ApiParam(value = "教师", required = true) @RequestBody List<Teacher> teacherList) {
        return ResponseObject.ofSuccess(teachingClassService.spiltClassForTeacher(taskId, teachingClassId, splitNum, hourType, teacherList));
    }

    @ApiOperation("批量添加教学班")
    @PostMapping("/addBatchTeachingClass")
    public ResponseObject<List<TeachingClass>> addTeachingClass(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                @ApiParam(value = "TeachingClass对象", required = true) @RequestBody List<TeachingClass> list) {
        return ResponseObject.ofSuccess(teachingClassService.addBatchTeachingClass(taskId,list));
    }

    @ApiOperation("按行政班生成教学班")
    @PostMapping("/addTeachingClassByClassId")
    public ResponseObject<List<TeachingClass>> addTeachingClassByClassId(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                         @ApiParam(value = "课程id", required = true) @RequestParam Long courseId,
                                                                         @ApiParam(value = "0无需选课 1在线选课 2:分级教学 3:预选教学班") @RequestParam(required = false) Integer teachingClassType,
                                                                         @ApiParam(value = "培养计划id", required = true) @RequestBody List<Integer> planIds) {
        return ResponseObject.ofSuccess(teachingClassService.addTeachingClassByClassId(taskId, courseId, teachingClassType, planIds));
    }

    @ApiOperation("根据教学班id获取学生列表")
    @GetMapping(value = "/getStudentsByTeachingClassId")
    public ResponseObject<PageInfo<Student>> getStudentsByTeachingClassId(@ApiParam(value = "教学班id", required = true) @RequestParam Long teachingClassId,
                                                                          @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                          @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                                          @ApiParam(value = "基础学院id") @RequestParam(required = false) String baseCollegeId,
                                                                          @ApiParam(value = "年级id") @RequestParam(required = false) String gradeId,
                                                                          @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                                          @ApiParam(value = "关键字模糊查询") @RequestParam(required = false) String keyword,
                                                                          @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        Page<Student> page = new Page<>(currentPage, pageSize);
        page.setOptimizeCountSql(false);
        return ResponseObject.ofSuccess(studentService.getStudentsByTeachingClassId(page, teachingClassId, baseCollegeId, gradeId, classId, keyword, taskId));
    }

    @ApiOperation("批量合班，合并教学班")
    @PostMapping("/combinedClass")
    public ResponseObject<Boolean> combinedClass(@ApiParam(value = "合并教学班id列表", required = true) @RequestBody List<Long> teachingClassIds,
                                                 @ApiParam(value = "目标教学班id", required = true) @RequestParam Long teachingClassId) {
        return ResponseObject.ofSuccess(teachingClassService.combinedClass(teachingClassIds, teachingClassId));
    }

    @ApiOperation("批量修改学生对应教学班")
    @PostMapping(value = "/updateTeachingClassStudent")
    public ResponseObject<Boolean> updateTeachingClassStudent(@ApiParam(value = "老的教学班id", required = true) @RequestParam Long oldTeachingClassId,
                                                              @ApiParam(value = "新的教学班id", required = true) @RequestParam Long newTeachingClassId,
                                                              @RequestBody List<Long> studentIds) {
        teachingClassStudentService.lambdaUpdate().eq(TeachingClassStudent::getTeachingClassId, oldTeachingClassId)
                .in(TeachingClassStudent::getStudentId, studentIds)
                .set(TeachingClassStudent::getTeachingClassId, newTeachingClassId)
                .update();
        return ResponseObject.ofSuccess(true);
    }

    @ApiOperation("批量删除教学班")
    @DeleteMapping("/removeTeachingClass")
    public ResponseObject<Integer> deleteTeachingClass(@ApiParam(value = "教学班id", required = true) @RequestBody List<Long> teachingClassIds) {
        if (CollUtil.isEmpty(teachingClassIds)) {
            throw new BizException("教学班id不能未空");
        }
        TeachingClass model = teachingClassService.getById(teachingClassIds.get(0));
        Course course = courseService.getById(model.getCourseId());
        Integer num = teachingClassService.deleteClass(teachingClassIds);
        List<TeachingClass> teachingClassList = teachingClassService.lambdaQuery().eq(TeachingClass::getCourseId, course.getCourseId()).list();
        if (CollUtil.isEmpty(teachingClassList)) {
            course.setTeachingSet(0);
            courseService.updateById(course);
        }
        return ResponseObject.ofSuccess(num);
    }

    @ApiOperation("清空课程所有教学班")
    @DeleteMapping("/clearTeachingClassByCourse")
    public ResponseObject<Integer> clearTeachingClassByCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                              @ApiParam(value = "课程id", required = true) @RequestParam Long courseId) {
        Course course = courseService.getById(courseId);
        List<Long> teachingClassIds = teachingClassService.lambdaQuery().eq(TeachingClass::getCourseId, courseId).eq(TeachingClass::getTaskId, taskId).eq(TeachingClass::getIsOptional, 0).list()
                .stream().map(TeachingClass::getTeachingClassId).collect(Collectors.toList());
        Integer integer = teachingClassService.deleteClass(teachingClassIds);
        List<TeachingClass> teachingClassList = teachingClassService.lambdaQuery().eq(TeachingClass::getCourseId, course.getCourseId()).list();
        if (CollUtil.isEmpty(teachingClassList)) {
            course.setTeachingSet(0);
            courseService.updateById(course);
        }
        return ResponseObject.ofSuccess(integer);
    }

    @ApiOperation("批量修改教学班周次参数")
    @PostMapping("/setTeachingClassWeek")
    public ResponseObject<Object> setTeachingClassWeek(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                       @ApiParam(value = "教学班周次实体类") @RequestBody(required = false) List<TeachingClassWeek> teachingClassWeeks) {
        return ResponseObject.ofSuccess(teachingClassService.setTeachingClassWeek(taskId, teachingClassWeeks));
    }

    @ApiOperation("批量修改教学班参数")
    @PostMapping("/setTeachingClass")
    public ResponseObject<Object> setTeachingClass(@ApiParam(value = "教学班实体类") @RequestBody(required = false) List<TeachingClass> teachingClassList) {
        teachingClassService.saveOrUpdateBatch(teachingClassList);
        return ResponseObject.ofSuccess(teachingClassList);
    }

    @ApiOperation("修改教学班名称")
    @GetMapping("/updateClassName")
    @Transactional(rollbackFor = Exception.class)
    public ResponseObject<Object> updateClassName(@ApiParam(value = "教学班实体类") @RequestParam Long teachingClassId,
                                                  @ApiParam(value = "教学班实体类") @RequestParam String teachingClassName) {
        List<TeachingClass> teachingClassList = teachingClassService.lambdaQuery().eq(TeachingClass::getTeachingClassName, teachingClassName).list();
        if (CollUtil.isNotEmpty(teachingClassList)) {
            throw new BizException("教学班名称不能重复");
        }
        boolean update = teachingClassService.lambdaUpdate().eq(TeachingClass::getTeachingClassId, teachingClassId).set(TeachingClass::getTeachingClassName, teachingClassName).update();
        boolean update1 = scheduleService.lambdaUpdate().eq(Schedule::getTeachingClassId, teachingClassId).set(Schedule::getTeachingClassName, teachingClassName).update();
        return ResponseObject.ofSuccess(update1);
    }

    @ApiOperation("设置教学班教师")
    @PostMapping(value = "/setTeacher")
    public ResponseObject<List<TeachingClassTeacher>> updateTeacher(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                    @ApiParam(value = "教学班id", required = true) @RequestParam Long teachingClassId,
                                                                    @ApiParam(value = "0:环节 1讲授 2实验 3上机 4其他", required = true) @RequestParam Integer hourType,
                                                                    @ApiParam(value = "1 自学设置教学班教师", required = false) @RequestParam(required = false) Integer type,
                                                                    @ApiParam(value = "1任课 2助教", required = true) @RequestParam Integer identity,
                                                                    @ApiParam(value = "教师") @RequestBody List<Teacher> teacherList) {
        return ResponseObject.ofSuccess(teachingClassService.updateTeacher(taskId, teachingClassId, hourType, teacherList, type, identity));
    }

    @ApiOperation("确认教学任务-获取教学班列表")
    @GetMapping("/getTeachingClassList")
    public ResponseObject<ResultDto<TeachingClass>> getTeachingClassHourList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                             @ApiParam(value = "1、课程 2、环节") @RequestParam(required = false) Integer courseOrLink,
                                                                             @ApiParam(value = "校区") @RequestParam(required = false) Integer campusId,
                                                                             @ApiParam(value = "行政班学院") @RequestParam(required = false) String baseCollegeId,
                                                                             @ApiParam(value = "年级") @RequestParam(required = false) String gradeId,
                                                                             @ApiParam(value = "专业id") @RequestParam(required = false) String baseMajorId,
                                                                             @ApiParam(value = "教学班名模糊查") @RequestParam(required = false) String keyword,
                                                                             @ApiParam(value = "教师id") @RequestParam(required = false) Long teacherId,
                                                                             @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                             @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        return ResponseObject.ofSuccess(teachingClassService.getTeachingClassHourList(currentPage, pageSize, taskId, courseOrLink, campusId, baseCollegeId, gradeId, baseMajorId, keyword, teacherId));
    }

    @ApiOperation("统计教学任务")
    @GetMapping("/publishStatistics")
    public ResponseObject<Object> publishStatistics(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(teachingClassService.publishStatistics(taskId));
    }

    @ApiOperation("获取检测记录")
    @GetMapping("/getMonitor")
    public ResponseObject<ResultDto<Monitor>> getMonitor(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                         @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                         @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize,
                                                         @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage) {
        return ResponseObject.ofSuccess(monitorService.getMonitor(taskId, baseCollegeId, pageSize, currentPage));
    }

    @ApiOperation("开始检测")
    @PostMapping("/addMonitor")
    public ResponseObject<List<MonitorRecord>> addMonitor(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                          @ApiParam(value = "基础平台学院id") @RequestParam(required = false) String baseCollegeId,
                                                          @ApiParam(value = "用户id", required = true) @RequestParam String userId,
                                                          @ApiParam(value = "用户名称", required = true) @RequestParam String userName,
                                                          @ApiParam(value = "入参实体类", required = true) @RequestBody Monitor param) {
        return ResponseObject.ofSuccess(monitorService.addMonitor(taskId, baseCollegeId, userId, userName, param));
    }

    @ApiOperation("查看检测结果")
    @GetMapping("/getMonitorRecord")
    public ResponseObject<List<MonitorRecord>> getMonitorRecord(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                @ApiParam(value = "监测记录id", required = true) @RequestParam Integer monitorId) {
        return ResponseObject.ofSuccess(monitorService.getMonitorRecord(taskId, monitorId));
    }

    @ApiOperation("根据课程id自动分配教师")
    @GetMapping(value = "/autoMatchTeacher")
    public ResponseObject<String> autoMatchTeacher(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                   @ApiParam(value = "课程id", required = false) @RequestParam(required = false) Long courseId) {
        return ResponseObject.ofSuccess(courseService.autoMatchTeacher(taskId, courseId));
    }

    @ApiOperation("获取指定年级对应的行政班列表")
    @GetMapping("/phyClassList")
    public ResponseObject<List<Map<String, Object>>> phyClassList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                  @ApiParam(value = "学院id") @RequestParam(required = false) String collegeId,
                                                                  @ApiParam(value = "年级id") @RequestParam(required = false) String gradeId) {
        return ResponseObject.ofSuccess(subClassService.phyClassList(taskId, collegeId, gradeId));
    }

    @ApiOperation("获取分组上课列表")
    @GetMapping("/getSubClassList")
    public ResponseObject<PageInfo<SubClass>> getSubClassList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                              @ApiParam(value = "分组名模糊查") @RequestParam(required = false) String keyword,
                                                              @ApiParam(value = "行政班学院") @RequestParam(required = false) String baseCollegeId,
                                                              @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                              @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        Page<SubClass> page = new Page<>(currentPage, pageSize);
        page.setOptimizeCountSql(false);
        return ResponseObject.ofSuccess(subClassService.getSubClassList(page, taskId, keyword, baseCollegeId));
    }

    @ApiOperation("批量删除分组")
    @DeleteMapping("/removeSubClass")
    public ResponseObject<Boolean> removeSubClass(@ApiParam(value = "分组唯一标识", required = true) @RequestBody List<String> uniqueShiftSigns) {
        return ResponseObject.ofSuccess(subClassService.removeSubClass(uniqueShiftSigns));
    }

    @ApiOperation("添加分组")
    @PostMapping("/addSubClass")
    public ResponseObject<Boolean> addSubClass(@ApiParam(value = "传参", required = true) @RequestBody SubClass subClass) {
        return ResponseObject.ofSuccess(subClassService.saveOrUpdate(subClass));
    }

//    @ApiOperation("添加上课组")
//    @PostMapping("/addClassGroup")
//    public ResponseObject<List<SubClassGroup>> addClassGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
//                                                             @ApiParam(value = "传参", required = true) @RequestBody List<SubClassGroup> param) {
//        return ResponseObject.ofSuccess(subClassService.addClassGroup(taskId, param));
//    }

    @ApiOperation("获取上课组列表")
    @GetMapping("/getClassGroupList")
    public ResponseObject<List<SubGroupVo>> getClassGroupList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                              @ApiParam(value = "分班唯一标识") @RequestParam(required = false) String uniqueShiftSign) {
        return ResponseObject.ofSuccess(teachingClassService.getClassGroupList(taskId, uniqueShiftSign));
    }

    @ApiOperation("删除上课组")
    @PostMapping("/removeClassGroup")
    public ResponseObject<Boolean> removeClassGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                    @ApiParam(value = "uuid", required = true) @RequestParam String uniqueShiftSign) {
        return ResponseObject.ofSuccess(subClassService.removeClassGroup(taskId, uniqueShiftSign));
    }

    @ApiOperation("确认教学计划-获取上课分组列表")
    @GetMapping("/getTeachingPlanClassList")
    public ResponseObject<PageInfo<SubClass>> getSubTeachingClassHourList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                          @ApiParam(value = "分组名模糊查") @RequestParam(required = false) String keyword,
                                                                          @ApiParam(value = "行政班学院") @RequestParam(required = false) String baseCollegeId,
                                                                          @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                          @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        Page<SubClass> page = new Page<>(currentPage, pageSize);
        page.setOptimizeCountSql(false);
        return ResponseObject.ofSuccess(subClassService.getSubTeachingClassHourList(page, taskId, keyword, baseCollegeId));
    }

    @ApiOperation("添加/更新指定课程对应的行政班列表-分组")
    @PostMapping("/updatePhyClassList")
    public ResponseObject<List<TeachingClass>> updatePhyClassList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                  @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                                  @ApiParam(value = "拆班id") @RequestParam(required = false) String uniqueShiftSign,
                                                                  @ApiParam(value = "课程id") @RequestBody(required = false) List<Long> courseIds) {
        return ResponseObject.ofSuccess(subClassService.updatePhyClassList(taskId, classId, uniqueShiftSign, courseIds));
    }

    @ApiOperation("生成拆班课程教学班")
    @PostMapping("/addSplitClassList")
    public ResponseObject<List<TeachingClass>> addSplitClassList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                 @ApiParam(value = "班级id") @RequestParam(required = false) String classId,
                                                                 @ApiParam(value = "拆班id") @RequestParam(required = false) String uniqueShiftSign,
                                                                 @ApiParam(value = "课程id") @RequestBody(required = false) List<Long> courseIds) {
        return ResponseObject.ofSuccess(splitClassService.addSplitClassList(taskId, classId, uniqueShiftSign, courseIds));
    }

    @ApiOperation("删除拆班课程")
    @PostMapping("/deleteSplitCourse")
    public ResponseObject<Boolean> deleteSplitCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                     @ApiParam(value = "uuid", required = true) @RequestParam() String uuid) {
        List<Long> teachingClassIds = teachingClassService.lambdaQuery().eq(TeachingClass::getSplitClassUuid, uuid).list()
                .stream().map(TeachingClass::getTeachingClassId).collect(Collectors.toList());
        Integer integer = teachingClassService.deleteClass(teachingClassIds);
        return ResponseObject.ofSuccess(integer == teachingClassIds.size());
    }

    @ApiOperation("获取拆班教学班")
    @GetMapping("/getSplitTeachingClass")
    public ResponseObject<List<TeachingClass>> getSplitTeachingClass(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                     @ApiParam(value = "拆班唯一标识", required = true) @RequestParam String uniqueShiftSign) {
        return ResponseObject.ofSuccess(splitClassService.getSplitTeachingClass(uniqueShiftSign));
    }

    @ApiOperation("添加拆班")
    @PostMapping("/addSplitClass")
    public ResponseObject<Boolean> addSplitClass(@ApiParam(value = "传参", required = true) @RequestBody SplitClass spiltClass) {
        return ResponseObject.ofSuccess(splitClassService.saveOrUpdate(spiltClass));
    }

    @ApiOperation("获取拆班上课列表")
    @GetMapping("/getSplitClassList")
    public ResponseObject<PageInfo<SplitClass>> getSplitClassList(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                  @ApiParam(value = "拆班名模糊查") @RequestParam(required = false) String keyword,
                                                                  @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                                  @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        return ResponseObject.ofSuccess(splitClassService.getSplitClassList(currentPage, pageSize, taskId, keyword));
    }

    @ApiOperation("批量删除拆班列表")
    @DeleteMapping("/removeSplitClass")
    public ResponseObject<Boolean> removeSplitClass(@ApiParam(value = "拆班唯一标识", required = true) @RequestBody List<String> uniqueShiftSigns) {
        return ResponseObject.ofSuccess(splitClassService.removeSplitClass(uniqueShiftSigns));
    }

    @ApiOperation("获取分组教学班")
    @GetMapping("/getSubTeachingClass")
    public ResponseObject<List<TeachingClass>> getSubTeachingClass(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                   @ApiParam(value = "分班唯一标识", required = true) @RequestParam String uniqueShiftSign) {
        return ResponseObject.ofSuccess(subClassService.getSubTeachingClass(uniqueShiftSign));
    }

    @ApiOperation("根据分组班级获取分组课程")
    @GetMapping("/getGroupCourse")
    public ResponseObject<List<Course>> getGroupCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                       @ApiParam(value = "班级id") @RequestParam(required = false) String classId) {
        return ResponseObject.ofSuccess(subClassService.getGroupCourse(taskId, classId));
    }

    @ApiOperation("设置分组课程教师")
    @PostMapping("/setGroupClassTeacher")
    public ResponseObject<List<TeachingClassTeacher>> groupClassTeacher(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                        @ApiParam(value = "uuid", required = true) @RequestParam String uuid,
                                                                        @ApiParam(value = "课程id", required = true) @RequestParam Long courseId,
                                                                        @ApiParam(value = "教师id") @RequestBody(required = false) List<Teacher> teacherList) {
        return ResponseObject.ofSuccess(subClassService.groupClassTeacher(taskId, uuid, courseId, teacherList));
    }

    @ApiOperation("设置分组课程参数")
    @PostMapping("/setGroupClassWeek")
    public ResponseObject<List<TeachingClassWeek>> groupClassWeek(@ApiParam(value = "uuid", required = true) @RequestParam String uuid,
                                                                  @ApiParam(value = "课程id", required = true) @RequestParam Long courseId,
                                                                  @ApiParam(value = "场地id") @RequestParam(required = false) Long roomId,
                                                                  @ApiParam(value = "场地类型id") @RequestParam(required = false) Integer roomType) {
        return ResponseObject.ofSuccess(subClassService.groupClassWeek(uuid, courseId, roomId, roomType));
    }

    @ApiOperation("删除分组课程")
    @PostMapping("/deleteGroupClassCourse")
    public ResponseObject<Boolean> deleteGroupClassCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                          @ApiParam(value = "uuid") @RequestParam(required = false) String uuid) {
        return ResponseObject.ofSuccess(subClassService.deleteGroupClassCourse(taskId, uuid));
    }

//    @ApiOperation("splitClassGroup")
//    @PostMapping("/splitClassGroup")
//    public ResponseObject<LinkedList<SubClassGroup>> splitClassGroup(@ApiParam(value = "待分教学班", required = true) @RequestBody List<TeachingClass> teachingClasses) {
//        return ResponseObject.ofSuccess(subClassService.splitClassGroup(teachingClasses));
//    }


//    @ApiOperation("删除分组教学班")
//    @PostMapping("/deleteGroup")
//    public ResponseObject<Boolean> deleteGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
//                                               @ApiParam(value = "uuid", required = true) @RequestParam Long uuid) {
//        return ResponseObject.ofSuccess(subClassService.deleteGroup(taskId, uuid));
//    }

    @GetMapping("/creatManualGroup")
    @ApiOperation("创建手动分组")
    public ResponseObject<String> creatManualGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                   @ApiParam(value = "uuid", required = true) @RequestParam String uuid) {
        return ResponseObject.ofSuccess(subClassService.creatManualGroup(taskId, uuid));
    }

    @ApiOperation("获取分组单班、双班列表，分组列表")
    @GetMapping("/groupOddEvenGroup")
    public ResponseObject<SubGroupDto> groupOddEvenGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                         @ApiParam(value = "分班标识", required = true) @RequestParam String uuid) {
        return ResponseObject.ofSuccess(subClassService.groupOddEvenGroup(taskId, uuid));
    }

    @ApiOperation("单双教学班添加至课程分组列表")
    @PostMapping("/addGroupToCourse")
    public ResponseObject<Boolean> addGroupToCourse(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                    @ApiParam(value = "uuid", required = true) @RequestParam String uuid,
                                                    @ApiParam(value = "分组id列表", required = true) @RequestBody List<Integer> ids) {
        return ResponseObject.ofSuccess(subClassService.addGroupToCourse(taskId, uuid, ids));
    }

    @ApiOperation("课程分组列表分解至单、双班")
    @PostMapping("/recoveryCourseGroup")
    public ResponseObject<Boolean> recoveryCourseGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                       @ApiParam(value = "uuid", required = true) @RequestParam String uuid,
                                                       @ApiParam(value = "分组id列表", required = true) @RequestBody List<Integer> ids) {
        return ResponseObject.ofSuccess(subClassService.recoveryCourseGroup(taskId, uuid, ids));
    }

    @ApiOperation("确认分组")
    @GetMapping("/confirmGroup")
    @LogAnnotation(operationType = "2", operationContent = "确认分组")
    public ResponseObject<String> confirmGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                               @ApiParam(value = "uuid", required = true) @RequestParam String uuid) {
        return ResponseObject.ofSuccess(subClassGroupService.confirmGroup(taskId, uuid));
    }

    @ApiOperation("获取课程参数设置个数")
    @GetMapping(value = "/getCourseParameterSet")
    public ResponseObject<CourseParameterSetVo> getCourseParameterSetVo(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(courseService.getCourseParameterSetVo(taskId));
    }

    @ApiOperation("获取本学期课程教学班数量")
    @GetMapping(value = "/getTeachingClassCount")
    public ResponseObject<Long> getTeachingClassNumByCourseId(@ApiParam(value = "课程id||环节id", required = true) @RequestParam Long courseId) {
        return ResponseObject.ofSuccess(teachingClassService.getTeachingClassNumByCourseId(courseId));
    }

//    @ApiOperation("根据课程id获取教学班列表")
//    @GetMapping(value = "/getByCourse")
//    public ResponseObject<List<TeachingClassVo>> getTeacherPlan(@ApiParam(value = "课程id||环节id", required = true) @RequestParam Long courseId) {
//        return ResponseObject.ofSuccess(teachingClassService.getTeachingClassByCourseId(courseId));
//    }

    @ApiOperation("分组详情-分组课程")
    @GetMapping("/getByUniqueShiftSign")
    public ResponseObject<List<SubCourseVo>> getByUniqueShiftSign(@ApiParam(value = "分班标识") @RequestParam(required = false) String uniqueShiftSign) {
        return ResponseObject.ofSuccess(subClassService.getByUniqueShiftSign(uniqueShiftSign));
    }

    @ApiOperation("将教学班拆成单个排课单元")
    @PostMapping("/convertSubClassGroup")
    public ResponseObject<List<SubClassGroup>> convertSubClassGroup(@ApiParam(value = "待分教学班", required = true) @RequestBody List<TeachingClass> teachingClasses) {
        return ResponseObject.ofSuccess(subClassService.convertSubClassGroup(teachingClasses));
    }

    @GetMapping("/autoGroup")
    @ApiOperation("单双号拆班自动分组")
    @LogAnnotation(operationType = "2", operationContent = "单双号拆班自动分组")
    public ResponseObject<List<SubGroupVo>> autoGroup(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                      @ApiParam(value = "分班标识", required = true) @RequestParam String uniqueShiftSign) {
        return ResponseObject.ofSuccess(subClassGroupService.autoGroup(taskId, uniqueShiftSign));
    }

    @ApiOperation("确认发布-教学计划")
    @PostMapping("/confirmTeachTask")
    public ResponseObject<Boolean> confirmTeachTask(@ApiParam(value = "基础平台学院id", required = true) @RequestBody List<String> baseCollegeIdList,
                                                    @ApiParam(value = "教学计划提交人id", required = true) @RequestParam String userId,
                                                    @ApiParam(value = "教学计划提交人姓名", required = true) @RequestParam String userName,
                                                    @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return ResponseObject.ofSuccess(teachingClassService.confirmTeachTask(baseCollegeIdList, userId, userName, taskId));
    }

}
